<?php
    include ($_SERVER["DOCUMENT_ROOT"]."/CTAN/config/ConnectDB.php");

    class buoibieudien extends ConnectDB{
        private $mabuoidien, $tenbuoidien, $diadiem, $chitietthem, $thoigianbatdau, $thoigiandien, $ngaydien, $vedanban;
        private $tableName="buoi_bieu_dien";
        public function getMaBuoiDien(){
            return $this->mabuoidien;
        }
        public function setMaBuoiDien($mabuoidien){
            $this->mabuoidien=$mabuoidien;
        }
        public function getTenBuoiDien(){
            return $this->tenbuoidien;
        }
        public function setTenBuoiDien($tenbuoidien){
            $this->tenbuoidien=$tenbuoidien;
        }
        public function getDiaDiem(){
            return $this->diadiem;
        }
        public function setDiaDiem($diadiem){
            $this->diadiem=$diadiem;
        }
        public function getChiTietThem(){
            return $this->chitietthem;
        }
        public function setChiTietThem($chitietthem){
            $this->chitietthem=$chitietthem;
        }
        public function getThoiGianBD(){
            return $this->thoigianbatdau;
        }
        public function setThoiGianBD($thoigianbatdau){
            $this->thoigianbatdau=$thoigianbatdau;
        }
        public function getThoiGianDien(){
            return $this->thoigiandien;
        }
        public function setThoiGianDien($thoigiandien){
            $this->thoigiandien=$thoigiandien;
        }
        public function getNgayDien(){
            return $this->ngaydien;
        }
        public function setNgayDien($ngaydien){
            $this->ngaydien=$ngaydien;
        }
        public function getVeDaBan(){
            return $this->vedanban;
        }
        public function setVeDaban($vedaban){
            $this->vedanban=$vedaban;
        }
        public function insertToDB(){
            //ma_buoi_dien, ten_buoi_dien, dia_diem, chi_tiet_them, thoi_gian_bat_dau, thoi_gian_dien, ngay_dien, ve_da_ban
            $insert_query = "INSERT INTO " .$this->tableName. " (ten_buoi_dien, dia_diem, chi_tiet_them, thoi_gian_bat_dau, thoi_gian_dien, ngay_dien, ve_da_ban) VALUES ('".
                    $this->tenbuoidien."','".$this->diadiem."','".$this->chitietthem."','".$this->thoigianbatdau."','".$this->thoigiandien."','".$this->ngaydien."','".$this->vedaban."')";
            $this->setQuery($insert_query);
            if ($this->executeQuery()){
                $getIdCommand = "SELECT MAX(ma_buoi_dien) as ma_buoi_dien FROM ".$this->tableName;
                $this->setQuery($getIdCommand);
                $result = $this->executeQuery();
                while ($row = mysql_fetch_array($result)) {
                    $this->mabuoidien=$row["ma_buoi_dien"];
                }
                //tra ve bien id de luu hinh
                return $this->mabuoidien;
            }
            else return $result;
            //return "conkhi";
        }
        public function updateToDB(){
            //ma_buoi_dien, ten_buoi_dien, dia_diem, chi_tiet_them, thoi_gian_bat_dau, thoi_gian_dien, ngay_dien, ve_da_ban
            $update_query = "UPDATE " .$this->tableName. " SET ten_buoi_dien='".$this->tenbuoidien."',
            dia_diem='".$this->diadiem."',
            chi_tiet_them='".$this->chitietthem."',
            thoi_gian_bat_dau='".$this->thoigianbatdau."',
            thoi_gian_dien='".$this->thoigiandien."',
            ngay_dien='".$this->ngaydien."' WHERE ma_buoi_dien='".$this->mabuoidien."'";
            $this->setQuery($update_query);
            if ($this->executeQuery()) return $this->mabuoidien;
            else return -1;
        }
        public function deleteFromDB(){
            $delete_query = "DELETE FROM " .$this->tableName. " WHERE ma_buoi_dien='".$this->mabuoidien."'";
            //mysql_close($connect);
            $this->setQuery($delete_query);
            return $this->executeQuery();
        }
        public function danhSachBuoiDien(){
            $query = "SELECT ma_buoi_dien, ten_buoi_dien, dia_diem, chi_tiet_them, thoi_gian_bat_dau, thoi_gian_dien, ngay_dien, ve_da_ban FROM buoi_bieu_dien";
            $this->setQuery($query);
            return $this->executeQuery();
        }
    }
?>